         <style lang="less">
// @import "./supplierManage.less";
.ivu-table-row-highlight td{
  color: #2d8cf0;
}
</style>
<template>
    <Modal :title="modalTitle" v-model="isShow" :mask-closable='false' :width="1000" @on-cancel="cancelSearch">   
      <!-- vue-modal BUG 外层加一个div会出现系统footer -->
      <!-- <div> --> 
        <Row>
            <Form ref="searchForm" :model="searchForm" inline :label-width="70" class="search-form">
                <Form-item label="商户名称" prop="supplierName">
                  <Input type="text" v-model="searchForm.supplierName" clearable placeholder="请输入商户名称" style="width: 200px"/>
                </Form-item>
                <Form-item label="手机号码" prop="mobile">
                  <Input type="text" v-model="searchForm.mobile" clearable placeholder="请输入手机号码" style="width: 200px"/>
                </Form-item>
                <Form-item style="margin-left:-35px;">
                  <Button @click="handleSearch" type="primary" icon="search">搜索</Button>
                  <Button @click="handleReset" type="ghost" style="margin-left:30px;">重置</Button>
                </Form-item>                          
            </Form>
        </Row>
        <Row class="margin-top-10 searchable-table-con1">
            <Table :loading="loading" border :columns="columns" :data="data" sortable="custom" @on-sort-change="changeSort" @on-selection-change="showSelect" ref="table" highlight-row @on-row-click="singleSelect"></Table>
            <!-- @on-row-click="singleSelect" -->
            <Table :columns="columns" :data="exportData" ref="exportTable" style="display:none"></Table>
        </Row>
        <Row type="flex" justify="end" class="code-row-bg page" style="margin-top:20px;">
            <Page :current="this.searchForm.pageNumber" :total="total" :page-size="this.searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50,100]" size="small" show-total show-elevator show-sizer></Page>
        </Row>
        <div slot="footer">
          <div style="float:left;width:200px;"><Alert type="warning" show-icon v-if="noSelectAlert">请选择商户</Alert></div>
          <Button type="text"  @click="cancelSearch">取消</Button>
          <Button type="primary" @click="sureSearch">确定</Button>
        </div>
      <!-- </div> -->
  </Modal>  
</template>

<script>

import dateFormatUtil from "@/utils/dateFormatUtil";

export default {
  name: "supplier-search-modal",
  data() {
    return {
      modalTitle: "商户查询",
      isShow: false,

      loading: true,

      selectCount: 0,
      selectList: [],
      selectTr: {},
      noSelectAlert: false,

      searchForm: { 
        supplierName: "",
        mobile: ""
      },
      modalType: 0,
      supplierModalVisible: false,

      province: "",
      city:"",

      errorPass: "",
      submitLoading: false,
      columns: [
        // {
        //   type: "selection",
        //   width: 60,
        //   align: "center"
        // },
        {
          title: "商户名称",
          key: "supplierName",
          width: 120,
          sortable: true
        },
        {
          title: "手机",
          key: "mobile",
          width: 120,
          sortable: true
        },
        {
          title: "联系人",
          key: "linkMan",
          width: 120,
          sortable: true
        },
        {
          title: "邮箱",
          key: "email",
          width: 120,
          sortable: true
        },
        // {
        //   title: "QQ",
        //   key: "qq",
        //   width: 120,
        //   sortable: true
        // },
        {
          title:"省",
          key:"province",
          width:120,
          sortable: true,
          align: "center",
          render: (h, params) => {
            if (params.row) {
              return h("span", 
                JSON.parse(params.row.province).name
              );
            }
          }
        },
        {
          title:"市",
          key:"city",
          width:120,
          sortable: true,
          align: "center",
          render: (h, params) => {
            if (params.row) {
              return h("span", 
                JSON.parse(params.row.city).name
              );
            }
          }
        },
        // {
        //   title: "联系电话",
        //   key: "telephone",
        //   width: 120,
        //   sortable: true
        // },
        
        //  {
        //   title:"详细地址",
        //   key:"address",
        //   width:120,
        //   sortable: true
        // },
        {
          title:"商户分类",
          key:"supplierType",
          width:116,
          sortable: true,
          render: (h, params) => {
            if (params.row) {
              if (params.row.supplierType === 0){
                return h("span", 
                  "普通商户"
                );
              }else{
                return h("span", 
                  "达人商户"
                );
              }
            }
          }
        },
        // {
        //   title:"商户介绍",
        //   key:"content",
        //   width:120,
        //   sortable: true
        // },
        {
          title: "审核状态",
          key: "status",
          align: "center",
          width: 130,
          render: (h, params) => {
            let re = "";
            if (params.row.status === 0) {
              return h("div", [
                h(
                  "Tag",
                  {
                    props: {
                      type: "dot",
                      color: "red"
                    }
                  },
                  "未审核"
                )
              ]);
            } else if (params.row.status === -1) {
              return h("div", [
                h(
                  "Tag",
                  {
                    props: {
                      type: "dot",
                      color: "red"
                    }
                  },
                  "未通过"
                )
              ]);
            } else if (params.row.status === 1) {
              return h("div", [
                h(
                  "Tag",
                  {
                    props: {
                      type: "dot",
                      color: "green"
                    }
                  },
                  "通过"
                )
              ]);
            }
          },
          filters: [
            {
              label: "未审核",
              value: 0
            },
            {
              label: "未通过",
              value: -1
            },
            {
              label: "通过",
              value: 1
            }
          ],
          filterMultiple: false,
          filterMethod(value, row) {
            if (value === 0) {
              return row.status === 0;
            } else if (value === -1) {
              return row.status === -1;
            } else if (value === 1) {
              return row.status === 1;
            }
          }
        },
      ],
      data: [],
      exportData: [],
      total: 0

    };
  },
 
  methods: {
    openSupplierSearchModal(){
      this.$refs.table.clearCurrentRow(); //清除高亮项，仅在开启 highlight-row 时可用
      this.isShow = true;
      this.selectTr = {};
    },
    singleSelect(e){
      this.selectTr = e;      
    },

    init() {
      this.getsupplierList();
      this.cleanSelectCount();
    },
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getsupplierList();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getsupplierList();
    },
    showSelect(e) {
      this.exportData = e;
      this.selectList = e;
      this.selectCount = e.length;
    },
    getsupplierList() {
      this.loading = true;  
      this.getRequest("/supplier/list", this.searchForm).then(res => {  
        this.loading = false;
        if (res.success === true) {
          console.log("listres:",res)
          this.data = res.result.content;
          this.total = res.result.totalElements;
        }
      });
    },

    cancelSearch() {
      this.isShow =  false;
      // this.$emit('on-close',true);
    },
    sureSearch(){
      if(this.selectTr.id){
        this.noSelectAlert = false;
        
        this.isShow = false;
        this.$emit('on-selected',this.selectTr);
      }else{
        this.noSelectAlert = true;
      }
      
    },

    handleSearch() {
      // console.log(this.resArr); 
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.init();
    },
    handleReset() {
      this.$refs.searchForm.resetFields();
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      // 重新加载数据
      this.init();
    },
    changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order === "normal") {
        this.searchForm.order = "";
      }
      this.init();
    },
    getRoleList() {
      this.getRequest("/role/getAllList").then(res => {
        if (res.success === true) {
          this.roleList = res.result;
        }
      });
    },
   
    cancelsupplier() {
      this.supplierModalVisible = false;
    },
  
    clearSelectAll() {
      this.$refs.table.selectAll(false);
      this.cleanSelectCount();
    },
    cleanSelectCount(){
      this.selectCount = 0;
    },
  },
  mounted() {
    this.init();
  }
};
</script>